package com.simba.server.commands.impl.record;

import com.simba.common.command.ICommand;
import com.simba.common.database.DbOperator;

public class RecordSlotPackHistoryCmd implements ICommand {
    public static final String NAME = "RecordSlotPackHistoryCmd";

    private final String columns = ""+
            "slotId, boxCode, syncFlag, boxType, uploadFlag, uploadNum, createTime, mailCount, planId, " +
            "roadSlot, printFlag, printerMaster, printerSlave, recordTime";

    private final int id;
    private final String sql = "insert into tt_slot_pack_history(" + columns + ") select "
            + columns + " from tt_slot_pack_info where id=?;";

    public RecordSlotPackHistoryCmd(int id)
    {
        this.id = id;
    }
    @Override
    public String getName() {
        return RecordSlotPackHistoryCmd.NAME;
    }

    @Override
    public Boolean run(Object params) {
        Boolean ret = false;

        if (!(params instanceof DbOperator))
        {
            return ret;
        }

        try
        {
            DbOperator dbOperator = (DbOperator) params;
            dbOperator.prepareStatement(this.sql);
            dbOperator.setInt(1, id);
            int rs = dbOperator.executeUpdate();

            if (rs > 0)
            {
                ret = true;
            }
        }
        catch (Exception ex)
        {
            ret = false;
        }

        return ret;
    }
}
